package cn.hackcloud.designpattern.command;

public class Invoker {
	private Command[] onCommands;
	private Command[] offCommands;
	Command undoCommand;

	public Invoker() {
		onCommands = new Command[5];
		offCommands = new Command[5];
		for (int i = 0; i < 5; i++) {
			onCommands[i] = new NoCommand();
			offCommands[i] = new NoCommand();
		}
	}

	// 设置命令
	public void setCommand(int number, Command on, Command off) {
		onCommands[number] = on;
		offCommands[number] = off;
	}

	// 按下按钮
	public void onButton(int no) {
		onCommands[no].execute();
		undoCommand = onCommands[no];
	}

	// 按下按钮
	public void offButton(int no) {
		offCommands[no].execute();
		undoCommand = offCommands[no];

	}

	// 按下按钮
	public void undoButton() {
		undoCommand.undo();
	}
}
